package com.atguigu.locks;

import java.util.concurrent.TimeUnit;

class Phone{
    public synchronized void sendEmail()
    {
        //暂停几秒钟线程
        try { TimeUnit.SECONDS.sleep(4); } catch (InterruptedException e) { e.printStackTrace(); }
        System.out.println("---Email");
    }

    public synchronized void sendSMS()
    {
        System.out.println("---SMS");
    }

    public void hello()
    {
        System.out.println("---hello");
    }
}
public class Lock8Demo {
    public static void main(String[] args) {
        Phone phone1=new Phone();
        Phone phone2=new Phone();
        new Thread(() -> {
            phone1.sendEmail();
        },"t1").start();

        //暂停毫秒
        try { TimeUnit.MILLISECONDS.sleep(30); } catch (InterruptedException e) { e.printStackTrace(); }

        new Thread(() -> {
            //phone.sendSMS();
            //phone.hello();
            phone2.sendSMS();
        },"t2").start();
    }
}
